/**
 * Copyright 2011 ArcBees Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package vn.nichecafe.client.ui.slider;

import java.util.ArrayList;
import java.util.List;

import org.vaadin.gwtgraphics.client.DrawingArea;
import org.vaadin.gwtgraphics.client.shape.Path;

import vn.nichecafe.client.NICHECafeUtils;
import vn.nichecafe.client.ui.UiModule;
import vn.nichecafe.client.ui.slider.content.ContentEnum;
import vn.nichecafe.client.ui.slider.content.GalleryPopupContent;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

/**
 * A simple menu that can be reused.
 * <p />
 * Instead of using a static field and {@code GWT.create(Binder.class)} to
 * instantiate the binder we rely on GIN dependency injection. This would
 * facilitate testing if we ever wanted to test this class outside of a
 * {@code GWTTestCase}.
 * <p />
 * Even though this widget contains an {@code @Inject} constructor, it can be
 * used within a UiBinder file. This is made possible by using GWTP's
 * {@link com.google.gwt.uibinder.rebind.GinUiBinderGenerator} and our use of
 * {@code &lt;inherits name="com.google.gwt.uibinder.GinUiBinder" /&gt} in
 * {@code Gwtptabsample.gwt.xml}. This also requires a method returning
 * {@link Hot} in {@link vn.nichecafe.client.gin.ClientGinjector
 * ClientGinjector}. Finally, it is good practice to bind the
 * {@link Hot.Binder} interface as a singleton, which is done in
 * {@link UiModule}.
 * 
 * @author Christian Goudreau
 * @author Philippe Beaudoin
 */
public class Hot extends Composite {

	/**
   */
	public interface Binder extends UiBinder<Widget, Hot> {
	}

	private static final Binder binder = GWT.create(Binder.class);

	@Inject
	public Hot() {
		initWidget(binder.createAndBindUi(this));
		initDrawArea();
	}

	@UiField
	FlowPanel sliderContent;
	
	
	private void initDrawArea() {
		List<Pos> listPos = new ArrayList<Pos>(0);
		listPos.add(new Pos(3,5));
		
		DrawingArea area = new DrawingArea(960, 425);
		Path path = new Path(50, 50);
		path.lineRelativelyTo(200, 200);
		path.lineRelativelyTo(100, 200);
		path.lineRelativelyTo(50, 100);
		path.lineRelativelyTo(50, 0);
		path.close();
		path.setFillOpacity(0);
		path.setStrokeOpacity(1);
		path.setStyleName("area-hover");
		path.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				sliderContent.removeStyleName("hot-bg");
				DialogBox dialogBox = NICHECafeUtils.createDialogBox(new GalleryPopupContent(ContentEnum.COCK_TAIL));
				dialogBox.show();
			}
		});
		path.addMouseOverHandler(new MouseOverHandler() {
			
			@Override
			public void onMouseOver(MouseOverEvent event) {
				sliderContent.addStyleName("hot-bg");
			}
		});
		path.addMouseOutHandler(new MouseOutHandler() {
			
			@Override
			public void onMouseOut(MouseOutEvent event) {
				sliderContent.removeStyleName("hot-bg");
			}
		});
		area.add(path);
		area.bringToFront(path);
		sliderContent.clear();
		sliderContent.add(area);
	}

}